package com.coszero.common.base;

/**
 * Desc： ViewPager的懒加载
 * <p>
 * Author： xmqian
 * Email:xmqian93@163.com
 * Date: 2019/6/4 19:46
 * @version 1
 */
public abstract class MyPagerLazyLoadFragment extends BaseFragment {
    private boolean isDataLoaded;

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        getLazyData();
    }

    @Deprecated
    @SuppressWarnings({"unchecked", "deprecation"})
    public void getLazyData() {
        if (getUserVisibleHint() && getView() != null) {
            if (!isDataLoaded) {
                lazyLoadData();
                isDataLoaded = true;
            }
        }
    }

    public abstract void lazyLoadData();
}
